package com.kai.steering.common.web.aop;

import com.kai.steering.common.web.vo.ReturnCodeExt;
import com.kai.steering.exception.UimpException;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @ Author     ：LiuKai.
 * @ Date       ：Created in 14:23 2022-3-10
 * @ Description：获取响应结果
 * @ Modified By：
 * @Version:
 */
@Slf4j
@Aspect
@Component
@Data
public class LogAop extends AbstractLogAop {


    @Pointcut("@annotation(com.kai.steering.common.web.aop.CtlLog) " +
            " || @within(com.kai.steering.common.web.aop.CtlLog) " +
            " || execution(public * com.kai.steering..*.ctl..*.*(..))")
    public void logPointCut() {
    }


    @Around("logPointCut()")
    @Override
    public Object doAround(ProceedingJoinPoint joinPoint) {
        try {
            return super.handle(joinPoint);
        } catch (UimpException ex) {
            throw ex;
        } catch (Throwable ex) {
            throw ReturnCodeExt.BUSINESS_EXCEPTION.getException(ex, ex.getMessage());
        }
    }

    /**
     * 异常通知 用于拦截记录异常日志
     *
     * @param joinPoint
     * @param e
     */
    @AfterThrowing(pointcut = "logPointCut()", throwing = "e")
    public void doAfterThrowing(JoinPoint joinPoint, Throwable e) {
        super.doException(joinPoint, e);
    }
}

